﻿@{
    ViewBag.Title = "固定资产出库列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Content/layer-v3.1.1/layer/layer.js"></script>
@section scripts{
    <script type="text/javascript">
        var boolSearch = true;

        //页面动态改动
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        });

        //页面初始化
        $(document).ready(function () {
            DisableBackspace();

            //取下拉框的值
            loadComboboxData();
            $("#dt_start").datebox("setValue", $.GetMonthFirstday()); //以当月第一天作为查询起始日期
            $("#dt_end").datebox("setValue", $.GetToday3()); //以当日为查询截止日期
            bindGrid(); //绑定dg数据

            //设置datagrid数据网格、网格上查询条件框、外部布局框的高度，以适应页面高度
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");

            //查询按钮点击事件
            $("#btnsearch").on("click", function () {
                reSearch();
            });

            //按下键盘上enter键触发查询按钮的点击事件
            $(document).keyup(function (event) {
                if (event.keyCode == 13) {
                    $("#btnsearch").trigger("click");
                }
            });

            //监听弹层页关闭按钮的点击事件
            $("#icon_close").on("click", function () {
                $("#layerPage").hide();
            });

        })

        //函数：绑定datagrid列表数据
        function bindGrid() {
            //获取查询条件
            var assetTypeID = $("#cmb_AssetType").combotree("getValue");//资产分类编码
            var materialID = $("#cmb_Asset").combogrid("getValue");//资产编码
            var assetID = $("#txt_AssetID").textbox("getValue"); //固定资产编号
            var startDate = $("#dt_start").datebox("getValue");//起始日期
            var endDate = $("#dt_end").datebox("getValue");//截止日期

            $('#grid').datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true, //条纹化
                singleSelect: true, //单选
                url: '@Url.Content("~/FixedAssets/FIXEDAssetsDelivery/GetDeliveryList")',
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页
                rownumbers: true,//显示行号
                pageSize: 20,//设置 页容量
                pageList: [10, 15, 20],//设置 页容量下拉框
                queryParams: {
                    assetTypeID: assetTypeID,
                    materialID: materialID,
                    assetID: assetID,
                    startDate: startDate,
                    endDate: endDate
                },
                columns: [[
                   { title: '编码', field: 'BianMa', width: '6%', align: "center", sortable: false, hidden: true },
                   { title: '资产编码', field: 'ZiChanBianMa', width: '6%', align: "center", sortable: false, hidden: true },
                   { title: '固定资产编号', field: 'GuDingZiChanBianHao', width: '8%', align: "center", sortable: false },
                   { title: '资产名称', field: 'ZiChanMingCheng', width: '8%', align: "center", sortable: false },
                   { title: '品牌', field: 'PinPai', width: '5%', align: "center", sortable: false },
                   { title: '型号', field: 'XingHao', width: '5%', align: "center", sortable: false },
                   //{ title: '规格', field: 'GuiGe', width: '5%', align: "center", sortable: false },
                   { title: '主机序列号', field: 'ZhuJiXuLieHao', width: '8%', align: "center", sortable: false },
                   //{ title: '单位', field: 'DanWei', width: '5%', align: "center", sortable: false },
                   //{ title: '数量', field: 'ShuLiang', width: '5%', align: "center", sortable: false },
                   { title: '单价(元)', field: 'DanJia', width: '5%', align: "center", sortable: false },
                   {
                       title: '出库日期', field: 'ChuKuShiJian', width: '6%', align: "center", sortable: false,
                       formatter: function (value, row, index) {
                           return $.formatDate(value);
                       }
                   },
                   { title: '出库仓库', field: 'ChuKuCangKu', width: '5%', align: "center", sortable: false },
                   { title: '入库仓库', field: 'RuKuCangKu', width: '5%', align: "center", sortable: false },
                   { title: '出库人', field: 'ChuKuRen', width: '5%', align: "center", sortable: false },
                   { title: '领用人', field: 'LingYongRen', width: '5%', align: "center", sortable: false },
                   { title: '出库存放点', field: 'ChuKuCunFangDian', width: '5%', align: "center", sortable: false },
                   { title: '入库存放点', field: 'RuKuCunFangDian', width: '5%', align: "center", sortable: false },
                   { title: '出库车牌号码', field: 'ChuKuChePaiHaoMa', width: '5%', align: "center", sortable: false },
                   { title: '入库车牌号码', field: 'RuKuChePaiHaoMa', width: '5%', align: "center", sortable: false },
                   { title: '设备管理科室', field: 'SheBeiGuanLiKeShi', width: '5%', align: "center", sortable: false },
                   {
                       title: '备注', field: 'BeiZhu', width: '8%', align: "center", sortable: false,
                       formatter: function (value, row, index) {
                           if (value) {
                               return "<span title=\"" + value + "\">" + value + "</span>";//鼠标悬浮显示title文字
                           } else {
                               return "";
                           }
                       }
                   },

                ]],
                toolbar: [{
                    iconCls: 'icon-add',
                    id: 'butnAdd',
                    text: "新增出库单",
                    handler: function () {
                        showLayerPage('@Url.Content("~/FixedAssets/FIXEDAssetsDelivery/DeliveryInfoEdit")' + '?State=new', '新增固定资产出库单', '900px', '90%');
                    }
                }, '-', {
                    iconCls: 'icon-edit',
                    id: 'butnEdit',
                    text: "修改出库单",
                    handler: function () {
                        var r = $('#grid').datagrid('getSelected');
                        if (r) {
                            showLayerPage('@Url.Content("~/FixedAssets/FIXEDAssetsDelivery/DeliveryInfoEdit")' + '?State=edit&Code=' + r.BianMa, '修改固定资产出库单', '900px', '90%');

                        }
                        else { $.messager.alert('提示信息', '请选择数据行！') }
                    }
                }
                , '-',
                {
                    iconCls: 'icon-clear',
                    text: "出库单详情",
                    handler: function () {
                        var r = $('#grid').datagrid('getSelected');
                        if (r) {
                            showLayerPage('@Url.Content("~/FixedAssets/FIXEDAssetsDelivery/DeliveryInfoEdit")' + '?State=view&Code=' + r.BianMa, '固定资产出库单详情', '900px', '90%');
                        }
                        else { $.messager.alert('提示信息', '请选择数据行！') }
                    }
                }

                //, '-',
                //{
                //    iconCls: 'icon-remove',
                //    text: "删除出库单",
                //    handler: function () {
                //        var r = $('#grid').datagrid('getSelected');
                //        if (r) {
                //            //console.log(r);
                //            deleteData(r.BianMa);
                //        }
                //        else { $.messager.alert('提示信息', '请选择数据行！') }
                //    }
                //}
                ],
                //add 20191107 plq 双击行查看详情页
                onDblClickRow: function (rowIndex, rowData) {
                    //console.log(rowData);
                    showLayerPage('@Url.Content("~/FixedAssets/FIXEDAssetsDelivery/DeliveryInfoEdit")' + '?State=view&Code=' + rowData.BianMa, '固定资产出库单详情', '900px', '90%');
                }
                //onLoadSuccess: function (data) {
                //    console.log(data);
                //}
            })
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        }

        //重新查询
        function reSearch() {
            //获取查询条件
            var assetTypeID = $("#cmb_AssetType").combotree("getValue");//资产分类编码
            var materialID = $("#cmb_Asset").combogrid("getValue");//资产编码
            var assetID = $("#txt_AssetID").textbox("getValue"); //固定资产编号
            var startDate = $("#dt_start").datebox("getValue");//起始日期
            var endDate = $("#dt_end").datebox("getValue");//截止日期

            //add20191107 plq start
            //解决查询按钮点击时 combotree组件未选择时 获取的值为undefined而不是""的问题
            if (assetTypeID == undefined) {
                assetTypeID = "";
            }
            //add20191107 plq end

            $('#grid').datagrid({
                pageNumber: 1,//点击查询返回第一页
                queryParams: {
                    assetTypeID: assetTypeID,
                    materialID: materialID,
                    assetID: assetID,
                    startDate: startDate,
                    endDate: endDate
                }
            })
        }

        @*//删除出库单
        function deleteData(code) {
            layer.confirm("确认要删除嘛？", {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: '@Url.Content("~/FixedAssets/FixedAssetsMaterial/DeleteData")',
                    data: {
                        code: code
                    },
                    success: function (data) {
                        layer.alert(data, function (index) {
                            layer.close(index);
                            $("#btnsearch").trigger("click"); //重新查询
                        });
                    }
                });
            })
        }*@


        //函数：加载combobox下拉框的值
        function loadComboboxData() {
            //固定资产分类
            $('#cmb_AssetType').combotree({
                url: '@Url.Content("~/FixedAssets/FixedAssetsDictionary/GetActiveAssetsTypeTree")',
                prompt: '--请选择--',
                onSelect: function (rec) {
                    //console.log(rec);
                    if (rec.id == "") {
                        return;
                    }
                    //根据分类取对应资产流水
                    var urlstr2 = '@Url.Content("~/FixedAssets/FixedAssetsDictionary/GetAssetListByType?typeId=")' + rec.id;
                    $("#cmb_Asset").combogrid({
                        prompt: '--请选择--',
                        panelWidth: 450,
                        idField: 'BianMa',
                        textField: 'ZiChanMingCheng',
                        url: urlstr2,
                        //editable: false,
                        columns: [[
                             { field: 'GuDingZiChanBianMa', title: '固定资产编号', width: 120, align: 'center' },
                             { field: 'ZiChanMingCheng', title: '固定资产名称', width: 120, align: 'center' },
                             { field: 'ZhuJiXuLieHao', title: '主机序列号', width: 120, align: 'center' },
                             { field: 'PinPai', title: '品牌', width: 45, align: 'center' },
                             { field: 'XingHao', title: '型号', width: 45, align: 'center' },
                             { field: 'GuiGe', title: '规格', width: 80, hidden: true },
                             { field: 'DanWei', title: '单位', width: 80, sortable: false, hidden: true }
                        ]],
                        fitColumns: true,
                        onLoadSuccess: function (data) {
                            console.log(data);
                        },
                        filter: function (inputText, row) {
                            var opts = $(this).combogrid('options');
                            if (row[opts.textField].indexOf(inputText) >= 0) {    //模糊匹配列
                                return true;
                            }
                        },
                        //filter: function (inputText, row) {
                        //    var opts = $(this).combogrid('options');
                        //    if (row[opts.groupField] == inputText) {
                        //        return true;
                        //    } else if (row[opts.textField] == inputText) {
                        //        return true;
                        //    } else {
                        //        if (boolSearch) {
                        //            boolSearch = false;
                        //            LoadFuzzyMatchListByInput(urlstr2, inputText);
                        //        }
                        //    }
                        //},
                        //onChange: function (n, o) {
                        //    if (n == "") {
                        //        LoadFuzzyMatchListByInput(urlstr2, n);
                        //    }
                        //},

                        //onSelect: function (rec) {
                        //    var g = $("#cmb_Asset").combogrid("grid");	// 获取数据表格对象
                        //    var r = g.datagrid('getSelected');	// 获取选择的行
                        //}
                    });
                    //LoadFuzzyMatchListByInput(urlstr2, "");

                }
            });


            //取所有固定资产流水
            var urlstr1 = '@Url.Content("~/FixedAssets/FixedAssetsDictionary/GetAssetList")';
            $("#cmb_Asset").combogrid({
                prompt: '--请选择--',
                panelWidth: 450,
                idField: 'BianMa',
                textField: 'ZiChanMingCheng',
                url: urlstr1,
                //editable:false,
                columns: [[
                     { field: 'GuDingZiChanBianMa', title: '固定资产编号', width: 120, align: 'center' },
                     { field: 'ZiChanMingCheng', title: '固定资产名称', width: 120, align: 'center' },
                     { field: 'ZhuJiXuLieHao', title: '主机序列号', width: 120, align: 'center' },
                     { field: 'PinPai', title: '品牌', width: 45, align: 'center' },
                     { field: 'XingHao', title: '型号', width: 45, align: 'center' },
                     { field: 'GuiGe', title: '规格', width: 80, hidden: true },
                     { field: 'DanWei', title: '单位', width: 80, sortable: false, hidden: true }
                ]],
                fitColumns: true,
                filter: function (inputText, row) {
                    var opts = $(this).combogrid('options');
                    if (row[opts.textField].indexOf(inputText) >= 0) {    //模糊匹配列
                        return true;
                    }
                },

                //delay: 500,//0.5s延时查询
                //keyHandler: {  //当用户按键后调用的函数
                //    up: function () { },  //实现空的up/down函数或者null，空的函数会覆盖combogrid 的默认行为，使键盘上下键失去上下滚动选中赋值效果，null 则会报错
                //    down: function () { },
                //    enter: function () { },
                //    query: function (q) {  //最后一个键的输入事件起，延迟触发的搜索事件。
                //        console.log("延迟触发的搜索事件参数q:" + q);
                //        if (q == "") {
                //            alert("输入为空")
                //        }

                //            ////加载模糊匹配列表
                //            if (boolSearch) {
                //                boolSearch = false;
                //                LoadFuzzyMatchListByInput(urlstr1, q);
                //            }


                //    }
                //},

                //filter: function (inputText, row) {
                //    console.log(inputText);
                //    var opts = $(this).combogrid('options');
                //    //console.log(opts);
                //    if (row[opts.textField] == inputText) {  //如果用户输入与该行的text显示字段一致，返回true选中该行
                //        //if (row[opts.textField].indexOf(q) >= 0)    //模糊匹配
                //        return true;
                //    }
                //    else {
                //        //加载模糊匹配列表---未实现
                //        if (boolSearch) {
                //            boolSearch = false;
                //            LoadFuzzyMatchListByInput(urlstr1, inputText);
                //        }
                //    }

                //},

                //onSelect: function (rowIndex, rowData) {
                //    console.log($("#cmb_Asset").combogrid("getValue"));
                //    //var g = $("#cmb_Asset").combogrid("grid");	// 获取数据表格对象
                //    //var r = g.datagrid('getSelected');	// 获取选择的行
                //},
                //onChange: function (newValue, oldValue) {   //value值发生变化
                //    console.log("新值为：---" + newValue);
                //    if (newValue == "") {
                //        LoadFuzzyMatchListByInput(urlstr1, newValue);
                //    }
                //},

            });


        }


        ////根据用户输入加载模糊匹配组合网格列表---测试有bug
        function LoadFuzzyMatchListByInput(url, inputText) {
            var rowArr = [];
            $.ajax({
                type: 'POST',
                url: url,
                dataType: "json",
                success: function (jsData) {
                    //console.log(inputText);
                    //console.log(jsData);
                    if (inputText == "") {  //如果输入为空，则加载全部列表
                        $("#cmb_Asset").combogrid("grid").datagrid("loadData", jsData);
                    } else {
                        for (var i = 0; i < jsData.length; i++) {
                            if (jsData[i].ZiChanMingCheng.indexOf(inputText) >= 0) { //匹配用户输入
                                rowArr.push(jsData[i]);
                            }
                        }
                        if (rowArr.length == 0) { //如果没有一个模糊匹配上
                            $("#cmb_Asset").combogrid("grid").datagrid("loadData", []);
                            //$("#cmb_Asset").combogrid("grid").datagrid("loadData", {rows:[],total:0});
                        } else {
                            console.log(rowArr);
                            $("#cmb_Asset").combogrid("grid").datagrid("loadData", rowArr);
                        }
                    }
                    boolSearch = true;
                }
            });
        }

        //2019-04-09 plq 显示弹层页面
        function showLayerPage(url, title, x, y) {
            $("#layerPageIframe").attr("src", url);
            $("#layerPage").css("width", x);
            $("#layerPage").css("height", y);
            $(".layerPage-title").html(title);
            $("#layerPage").show();
        }

        //2019-04-09 plq 隐藏弹层页面并重新查询页面
        function hideLayerPage() {
            $("#layerPage").hide();
            $("#layerPageIframe").attr("src", "");//iframe src置为空，防止下次打开时页面切换闪烁
            lnk = document.getElementById("btnsearch");
            lnk.click();
        }

        //2019-04-09 plq 隐藏弹层页面并重载页面
        function reload() {
            $("#layerPage").hide();
            $("#layerPageIframe").attr("src", "");//iframe src置为空，防止下次打开时页面切换闪烁
            location.reload();
        }

        //给easyui combotree增添清空按钮
        $.fn.combotree.defaults.icons = [{
            iconCls: 'icon-clear',
            handler: function (e) {
                $(e.handleObj.data.target).combotree('clear');
            }
        }];

        //给easyui combogrid增添清空按钮
        $.fn.combogrid.defaults.icons = [{
            iconCls: 'icon-clear',
            handler: function (e) {
                $(e.handleObj.data.target).combogrid('clear');
            }
        }];

    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'固定资产出库记录',iconCls:'icon-custom-Entry'">
        <div id="SearchBar" data-options="region:'center'" style="overflow: hidden; padding: 10px">
            <table style="width:99%" cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td align="right" valign="middle" width="8%">分类：</td>
                    <td align="right" valign="middle" width="15%">
                        <input id="cmb_AssetType" class="easyui-combotree" style="width:200px;" />
                    </td>
                    <td align="right" valign="middle" width="8%">资产：</td>
                    <td align="right" valign="middle" width="15%">
                        <input type="text" id="cmb_Asset" class="easyui-combogrid" style="width: 200px;" />
                    </td>
                    <td align="right" valign="middle" width="8%">固定资产编号：</td>
                    <td align="right" valign="middle" width="15%">
                        <input type="text" id="txt_AssetID" class="easyui-textbox" style="width: 200px;" />
                    </td>
                    <td align="center" valign="middle" width="8%">
                        &nbsp;
                    </td>
                    <td align="center" valign="middle" width="15%">
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
                    </td>
                    <td align="center" valign="middle">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle">出库日期：</td>
                    <td align="right" valign="middle">
                        <input class="easyui-datebox" id="dt_start" style="width: 200px;" />
                    </td>
                    <td align="right" valign="middle">至：</td>
                    <td align="right" valign="middle">
                        <input class="easyui-datebox" id="dt_end" style="width: 200px;" />
                    </td>
                    <td align="right" valign="middle" colspan="5">&nbsp;</td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="grid"></table>
        </div>
    </div>
</div>

<!--弹层页div-->
<div class="layerPage" id="layerPage" style="display:none;">
    <div class="layerPage-title" style="cursor: move;">弹层页</div>
    <span class="icon_close_box">
        <a class="icon_close" id="icon_close" href="javascript:;" style="background-image:url('@Url.Content("~/Images/icon/icon.png")')"></a>
    </span>
    <iframe id='layerPageIframe' style="width:100%;height:100%"></iframe>
</div>
<!--弹层页样式-->
<style>
    .layerPage {
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        width: 900px;
        height: 650px;
        margin: 0;
        padding: 0;
        padding-top: 42px;
        background-color: #fff;
        border-radius: 2px;
        box-shadow: 1px 1px 50px rgba(0,0,0,.3);
        box-sizing: border-box;
    }

    .layerPage-title {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        padding: 0 80px 0 20px;
        height: 42px;
        line-height: 42px;
        border-bottom: 1px solid #eee;
        font-size: 14px;
        color: #333;
        overflow: hidden;
        background-color: #F8F8F8;
        border-radius: 2px 2px 0 0;
        text-overflow: ellipsis;
        white-space: nowrap;
        box-sizing: border-box;
        -moz-user-select: none;
        -o-user-select: none;
        -khtml-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }

    .layerPage iframe {
        border: none;
        width: 100%;
        height: 100%;
    }

    .icon_close_box {
        position: absolute;
        right: 15px;
        *right: 0;
        top: 15px;
        font-size: 0;
        line-height: initial;
        box-sizing: border-box;
    }

    .icon_close {
        display: inline-block;
        *display: inline;
        *zoom: 1;
        vertical-align: top;
        background-position: 1px -40px;
        cursor: pointer;
        width: 16px;
        height: 16px;
        margin-left: 10px;
        font-size: 12px;
        box-sizing: border-box;
        background-repeat: no-repeat;
    }
</style>
<style>
    .datagrid-header-row .datagrid-cell span {
        white-space: normal !important;
        word-wrap: normal !important;
    }
</style>
